package nojava;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class Dog {
    private Lock lock1 = new ReentrantLock();
    public void fn1(){
        lock1.lock();
        System.out.println(Thread.currentThread().getName()+":拿到lock1 ,  等待lock2");
        try {Thread.sleep(1);} catch (InterruptedException e) {throw new RuntimeException(e);}
        fn2();
        lock1.unlock();
    }


    private Lock lock2 = new ReentrantLock();
    public void fn2(){
        lock2.lock();
        System.out.println(Thread.currentThread().getName()+":拿到lock2 ,  等待lock1");
        try {Thread.sleep(1);} catch (InterruptedException e) {throw new RuntimeException(e);}
        fn1();
        lock2.unlock();
    }
}
